//package com.xw.bo.ks.client;

//import com.alibaba.fastjson.JSON;
//import com.kuaishou.merchant.open.api.KsMerchantApiException;
//import com.kuaishou.merchant.open.api.client.oauth.OauthAccessTokenKsClient;
//import com.kuaishou.merchant.open.api.common.dto.KsHttpResponseDTO;
//import com.kuaishou.merchant.open.api.common.utils.LoggerUtils;
//import com.kuaishou.merchant.open.api.common.utils.RequestCheckUtils;
//import com.kuaishou.merchant.open.api.response.oauth.KsAccessTokenResponse;
//import lombok.extern.slf4j.Slf4j;
//
//import java.io.IOException;
//import java.util.HashMap;
//import java.util.Map;
//
//@Slf4j
//public class KsTokenClient extends OauthAccessTokenKsClient {
//
//    public KsTokenClient(String appKey, String appSecret) {
//        super(appKey, appSecret);
//    }
//
//    public KsTokenClient(String appKey, String appSecret, String serverRestUrl) {
//        super(appKey, appSecret, serverRestUrl);
//    }
//
//    public KsTokenClient(String appKey, String appSecret, int connectTimeout, int readTimeout) {
//        super(appKey, appSecret, connectTimeout, readTimeout);
//    }
//
//
//    @Override
//    public KsAccessTokenResponse getAccessToken(String code) throws KsMerchantApiException {
//        RequestCheckUtils.checkNotEmpty(this.appKey, "appKey");
//        RequestCheckUtils.checkNotEmpty(this.appSecret, "appSecret");
//        KsHttpResponseDTO httpResponseDTO = null;
//        try {
//            httpResponseDTO = getHttpClient().doGet(this.serverRestUrl + "/oauth2/access_token", this.buildOauthAccessTokenRequest(code), "UTF-8", (Map) null, this.getProxy());
//            KsAccessTokenResponse response = JSON.parseObject(httpResponseDTO.getBody(), KsAccessTokenResponse.class);
//            if (response == null) {
//                log.info("ks请求结果：{}", JSON.toJSON(httpResponseDTO));
//                throw new KsMerchantApiException("ks oauth access_token api responseBody parse fail");
//            } else {
//                return response;
//            }
//        } catch (IOException var4) {
//            log.info("ks请求结果：{}", JSON.toJSON(httpResponseDTO));
//            LoggerUtils.logApiError(logger, this.appKey, "ks.oauth.access.token", "https://openapi.kwaixiaodian.com/oauth2/access_token", (Map) null, var4);
//            throw new KsMerchantApiException(var4);
//        }
//    }
//
//    @Override
//    public KsAccessTokenResponse refreshAccessToken(String refreshToken) throws KsMerchantApiException {
//        RequestCheckUtils.checkNotEmpty(this.appKey, "appKey");
//        RequestCheckUtils.checkNotEmpty(this.appSecret, "appSecret");
//        KsHttpResponseDTO httpResponseDTO = null;
//        try {
//            httpResponseDTO = getHttpClient().doGet(this.serverRestUrl + "/oauth2/refresh_token", this.buildOauthRefreshTokenRequest(refreshToken), "UTF-8", (Map) null, this.getProxy());
//
//            KsAccessTokenResponse response = JSON.parseObject(httpResponseDTO.getBody(), KsAccessTokenResponse.class);
//            if (response == null) {
//                log.info("ks请求结果：{}", JSON.toJSON(httpResponseDTO));
//                throw new KsMerchantApiException("ks oauth refresh_token api responseBody parse fail");
//            } else {
//                return response;
//            }
//        } catch (IOException var4) {
//            log.info("ks请求结果：{}", JSON.toJSON(httpResponseDTO));
//            LoggerUtils.logApiError(logger, this.appKey, "ks.oauth.refresh.token", "https://openapi.kwaixiaodian.com/oauth2/access_token", (Map) null, var4);
//            throw new KsMerchantApiException(var4);
//        }
//    }
//
//
//    private Map<String, String> buildOauthAccessTokenRequest(String code) {
//        Map<String, String> requestParams = new HashMap();
//        requestParams.put("app_id", this.getAppKey());
//        requestParams.put("app_secret", this.getAppSecret());
//        requestParams.put("grant_type", "code");
//        requestParams.put("code", code);
//        return requestParams;
//    }
//
//    private Map<String, String> buildOauthRefreshTokenRequest(String refreshToken) {
//        Map<String, String> requestParams = new HashMap();
//        requestParams.put("app_id", this.getAppKey());
//        requestParams.put("app_secret", this.getAppSecret());
//        requestParams.put("grant_type", "refresh_token");
//        requestParams.put("refresh_token", refreshToken);
//        return requestParams;
//    }
//}
